package com.atguigu.gmall.user.controller;


import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.user.service.UserInfoService;
import com.atguigu.gmall.user.vo.UserLoginSuccessVo;
import com.atguigu.gmall.user.vo.UserLoginVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@RequestMapping("/api/user")
@RestController
public class UserLoginController {

    @Autowired
    UserInfoService userInfoService;

    @PostMapping("/passport/login")
    public Result login(@RequestBody UserLoginVo vo, HttpServletRequest request,
                        HttpServletResponse response){

        UserLoginSuccessVo successVo = userInfoService.login(vo);

        return Result.ok(successVo);
    }


    // 用户退出
    @GetMapping("/passport/logout")
    public Result logout(@RequestHeader("token") String token){

        //只要退出成功，前端自己删掉cookie；后台也要自己删除这个用户
        userInfoService.logout(token);
        return Result.ok();
    }
}
